package com.zhiyou100.service.imp;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;import org.springframework.web.bind.annotation.RequestMapping;

import com.zhiyou100.IService.IserviceGo;
import com.zhiyou100.entity.prosGo.TbProjects;
import com.zhiyou100.entity.prosGo.TbProjectsExample;
import com.zhiyou100.entity.prosGo.TbProjectsExample.Criteria;
import com.zhiyou100.entity.prosGo.TbRepay;
import com.zhiyou100.entity.prosGo.TbUser;
import com.zhiyou100.mapper.prosGo.TbProjectsMapper;
import com.zhiyou100.mapper.prosGo.TbRepayMapper;
import com.zhiyou100.mapper.prosGo.TbUserMapper;

@Service
public class ServiceGoImp implements IserviceGo {

	@Resource
	private TbUserMapper mapperUser;
	@Resource
	private TbRepayMapper mapperRepay;
	@Resource
	private TbProjectsMapper mapperPro;
	
	public int progo1(TbUser user, TbProjects pro) {
		pro.setPsUsId(user.getUsId());
		pro.setPsStatus(0);
		int num = mapperPro.insert(pro);
		if (num>0) {
			TbProjectsExample example = new TbProjectsExample();
			Criteria criteria = example.createCriteria();
			criteria.andPsUsIdEqualTo(user.getUsId());
			criteria.andPsCustNameEqualTo(pro.getPsCustName());
			criteria.andPsCustPhoneEqualTo(pro.getPsCustPhone());
			criteria.andPsCustAddressEqualTo(pro.getPsCustAddress());
			List<TbProjects> list = mapperPro.selectByExample(example);
			return list.get(0).getPsId();
		}
		return -1;
	}

	public boolean progo2(TbProjects pro) {
		TbProjectsExample example = new TbProjectsExample();
		Criteria criteria = example.createCriteria();
		criteria.andPsIdEqualTo(pro.getPsId());
		pro.setPsId(null);
		int num = mapperPro.updateByExampleSelective(pro, example);
		return num>0?true:false;
	}

	public boolean progo4(TbRepay repay) {
		int num = mapperRepay.insert(repay);
		return num>0?true:false;
	}
}